package com.itcast.googleplay.holder;

import com.itcast.googleplay.R;
import com.itcast.googleplay.domain.AppInfo;
import com.itcast.googleplay.http.CZApi;
import com.itcast.googleplay.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class AppInfoHolder extends BaseHolder<AppInfo>{

	private TextView tvName,tvDownloadNumber,tvVersion,tvPubDate,tvSize;
	private ImageView ivIcon;
	private RatingBar bar;
	private DisplayImageOptions options;

	@Override
	public void initData() {
		AppInfo appInfo = getData();
		tvName.setText(appInfo.name);
		tvDownloadNumber.setText("下载量:"+appInfo.downloadNum);
		tvVersion.setText("版本名称:"+appInfo.version);
		tvPubDate.setText("发布时间:"+appInfo.date);
		tvSize.setText("应用大小:"+Formatter.formatFileSize(UIUtils.getContext(), appInfo.size));
		bar.setRating(appInfo.stars);
		
		//ImageLoader
		//初始图片缓存方式代码
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.ic_default)//在加载图片的时候,展示的默认图片
				
				.showImageForEmptyUri(R.drawable.ic_default)//uri传递出现问题时展示的图片
				
				.showImageOnFail(R.drawable.ic_default)//加载网络失败的时候,展示的图片
				
				.cacheInMemory(true)//是否需要内存缓存
				
				.cacheOnDisk(true)//是否需要磁盘缓存
				
				.considerExifParams(true)//是否支持图片自动调整,让其正常图像显示
		
				.build();//设置圆角半径
		ImageLoader.getInstance().displayImage(CZApi.BASEIMGURL+appInfo.iconUrl, ivIcon,options);
	}

	@Override
	public View initView() {
		View view = UIUtils.inflate(R.layout.layout_detail_app_info);
		ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
		
		bar = (RatingBar) view.findViewById(R.id.ratingbar);
		
		tvName = (TextView) view.findViewById(R.id.tv_name);
		tvDownloadNumber = (TextView) view.findViewById(R.id.tv_download_number);
		tvVersion = (TextView) view.findViewById(R.id.tv_version);
		tvPubDate = (TextView)view.findViewById(R.id.tv_pub_date);
		tvSize = (TextView)view.findViewById(R.id.tv_size);
		
		return view;
	}

}
